// 链表删除给定值

// 头结点可能是需要删除的值, 可能需要换头结点 ,先找到新的头结点


function ListNode(val, next) {
    this.val = (val === undefined ? 0 : val)
    this.next = (next === undefined ? null : next)
}


function removeVal(head, val) {
    while (head !== null) {
        if (head.val !== val) {
            break;
        }
        head = head.next
    }

    let pre = head
    let cur = head
    while (head !== null) {
        if (head === val) {
            pre.next = cur.next
        } else {
            pre = cur
        }
        cur = cur.next
    }

    return head
}
